package com.woniuxy.woniuhis.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.woniuxy.woniuhis.interceptor.LoginHandlerInterceptor;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	
	@Autowired
	LoginHandlerInterceptor loginHandlerInterceptor;
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		// 这里匹配了所有的URL，允许所有的外域发起跨域请求，允许外域发起请求任意HTTP Method，允许跨域请求包含任意的头信息。
		registry.addMapping("/**")

				.allowedHeaders("*")

				.allowedMethods("*")

				.allowedOrigins("*")

				.allowCredentials(true);
	}

	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		// 注册自定义映射路径
		registry.addViewController("/main").setViewName("views/login.html");
		registry.addViewController("/").setViewName("views/login.html");
	}

	// 添加拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(loginHandlerInterceptor).addPathPatterns("/**").excludePathPatterns("/login",
				"/js/**", "/layuiadmin/**", "/views/register.html",
				"/views/login.html", "/main", "/register","/generateVerifyCode");
	}

}